<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Models\Permission
 *
 * @property int $id
 * @property boolean $parentid
 * @property string $name
 * @property string $api_route
 * @property string $web_route
 * @property string $method
 * @property string $desc
 * @property int $no
 * @property boolean $is_need_auth
 * @property boolean $is_system_menu
 * @property boolean $status
 * @property string $updated_at
 * @property string $created_at
 * @method static \Illuminate\Database\Eloquent\Builder|Permission newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Permission newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|Permission query()
 * @method static \Illuminate\Database\Eloquent\Builder|Permission whereApiRoute($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Permission whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Permission whereDesc($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Permission whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Permission whereIsNeedAuth($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Permission whereIsSystemMenu($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Permission whereMethod($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Permission whereName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Permission whereNo($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Permission whereParentid($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Permission whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Permission whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|Permission whereWebRoute($value)
 * @mixin \Eloquent
 */
class Permission extends Model
{
    /**
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'permission';
    public $timestamps = false;
    /**
     * @var array
     */
    protected $fillable = ['parentid', 'name', 'api_route', 'web_route', 'method', 'desc', 'no','controller','functions', 'is_need_auth', 'is_system_menu', 'status', 'updated_at', 'created_at'];


    public function roles(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
    {
        return $this->belongsToMany('App\Models\Role');
    }
    public function users(): \Illuminate\Database\Eloquent\Relations\BelongsToMany
    {
        return $this->belongsToMany('App\Models\Users');
    }

    public function children(): \Illuminate\Database\Eloquent\Relations\HasMany
    {
        return $this->hasMany(Permission::class,'parentid')->where('status',1)->select(['id','parentid','name as label','method','status']);
    }
    public function parent(): \Illuminate\Database\Eloquent\Relations\BelongsTo
    {
        return $this->belongsTo(Permission::class,'parentid');
    }
}
